

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>federatedml.param.feature_binning_param &mdash; FATE 1.0 documentation</title>
  

  
  
  
  

  
  <script type="text/javascript" src="../../../_static/js/modernizr.min.js"></script>
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
        <script type="text/javascript" src="../../../_static/jquery.js"></script>
        <script type="text/javascript" src="../../../_static/underscore.js"></script>
        <script type="text/javascript" src="../../../_static/doctools.js"></script>
        <script type="text/javascript" src="../../../_static/language_data.js"></script>
    
    <script type="text/javascript" src="../../../_static/js/theme.js"></script>

    

  
  <link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
    <link rel="index" title="Index" href="../../../genindex.html" />
    <link rel="search" title="Search" href="../../../search.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="../../../index.html" class="icon icon-home"> FATE
          

          
          </a>

          
            
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <!-- Local TOC -->
              <div class="local-toc"></div>
            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../../index.html">FATE</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../../index.html">Docs</a> &raquo;</li>
        
          <li><a href="../../index.html">Module code</a> &raquo;</li>
        
      <li>federatedml.param.feature_binning_param</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <h1>Source code for federatedml.param.feature_binning_param</h1><div class="highlight"><pre>
<span></span><span class="ch">#!/usr/bin/env python</span>
<span class="c1"># -*- coding: utf-8 -*-</span>

<span class="kn">import</span> <span class="nn">copy</span>

<span class="c1">#</span>
<span class="c1">#  Copyright 2019 The FATE Authors. All Rights Reserved.</span>
<span class="c1">#</span>
<span class="c1">#  Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);</span>
<span class="c1">#  you may not use this file except in compliance with the License.</span>
<span class="c1">#  You may obtain a copy of the License at</span>
<span class="c1">#</span>
<span class="c1">#      http://www.apache.org/licenses/LICENSE-2.0</span>
<span class="c1">#</span>
<span class="c1">#  Unless required by applicable law or agreed to in writing, software</span>
<span class="c1">#  distributed under the License is distributed on an &quot;AS IS&quot; BASIS,</span>
<span class="c1">#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span>
<span class="c1">#  See the License for the specific language governing permissions and</span>
<span class="c1">#  limitations under the License.</span>
<span class="c1">#</span>
<span class="kn">from</span> <span class="nn">federatedml.param.base_param</span> <span class="k">import</span> <span class="n">BaseParam</span>
<span class="kn">from</span> <span class="nn">federatedml.util</span> <span class="k">import</span> <span class="n">consts</span>


<div class="viewcode-block" id="TransformParam"><a class="viewcode-back" href="../../../federatedml.param.html#federatedml.param.feature_binning_param.TransformParam">[docs]</a><span class="k">class</span> <span class="nc">TransformParam</span><span class="p">(</span><span class="n">BaseParam</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Define how to transfer the cols</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    transform_cols : list of column index, default: -1</span>
<span class="sd">        Specify which columns need to be transform. If column index is None, None of columns will be transformed.</span>
<span class="sd">        If it is -1, it will use same columns as cols in binning module.</span>

<span class="sd">    transform_type: str, &#39;bin_num&#39;or None default: None</span>
<span class="sd">        Specify which value these columns going to replace. If it is set as None, nothing will be replaced.</span>

<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">transform_cols</span><span class="o">=-</span><span class="mi">1</span><span class="p">,</span> <span class="n">transform_type</span><span class="o">=</span><span class="s2">&quot;bin_num&quot;</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">(</span><span class="n">TransformParam</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">transform_cols</span> <span class="o">=</span> <span class="n">transform_cols</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">transform_type</span> <span class="o">=</span> <span class="n">transform_type</span>

<div class="viewcode-block" id="TransformParam.check"><a class="viewcode-back" href="../../../federatedml.param.html#federatedml.param.feature_binning_param.TransformParam.check">[docs]</a>    <span class="k">def</span> <span class="nf">check</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">descr</span> <span class="o">=</span> <span class="s2">&quot;Transform Param&#39;s &quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">transform_cols</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">transform_cols</span> <span class="o">!=</span> <span class="o">-</span><span class="mi">1</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">check_defined_type</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">transform_cols</span><span class="p">,</span> <span class="n">descr</span><span class="p">,</span> <span class="p">[</span><span class="s1">&#39;list&#39;</span><span class="p">])</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">check_defined_type</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">transform_type</span><span class="p">,</span> <span class="n">descr</span><span class="p">,</span> <span class="p">[</span><span class="s1">&#39;bin_num&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">])</span></div></div>


<div class="viewcode-block" id="FeatureBinningParam"><a class="viewcode-back" href="../../../federatedml.param.html#federatedml.param.feature_binning_param.FeatureBinningParam">[docs]</a><span class="k">class</span> <span class="nc">FeatureBinningParam</span><span class="p">(</span><span class="n">BaseParam</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Define the feature binning method</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    method : str, &#39;quantile&#39; or &#39;bucket&#39;, default: &#39;quantile&#39;</span>
<span class="sd">        Binning method.</span>

<span class="sd">    compress_thres: int, default: 10000</span>
<span class="sd">        When the number of saved summaries exceed this threshold, it will call its compress function</span>

<span class="sd">    head_size: int, default: 10000</span>
<span class="sd">        The buffer size to store inserted observations. When head list reach this buffer size, the</span>
<span class="sd">        QuantileSummaries object start to generate summary(or stats) and insert into its sampled list.</span>

<span class="sd">    error: float, 0 &lt;= error &lt; 1 default: 0.001</span>
<span class="sd">        The error of tolerance of binning. The final split point comes from original data, and the rank</span>
<span class="sd">        of this value is close to the exact rank. More precisely,</span>
<span class="sd">        floor((p - 2 * error) * N) &lt;= rank(x) &lt;= ceil((p + 2 * error) * N)</span>
<span class="sd">        where p is the quantile in float, and N is total number of data.</span>

<span class="sd">    bin_num: int, bin_num &gt; 0, default: 10</span>
<span class="sd">        The max bin number for binning</span>

<span class="sd">    cols : list of int or int, default: -1</span>
<span class="sd">        Specify which columns need to calculated. -1 represent for all columns. If you need to indicate specific</span>
<span class="sd">        cols, provide a list of header index instead of -1.</span>

<span class="sd">    adjustment_factor : float, default: 0.5</span>
<span class="sd">        the adjustment factor when calculating WOE. This is useful when there is no event or non-event in</span>
<span class="sd">        a bin.</span>

<span class="sd">    local_only : bool, default: False</span>
<span class="sd">        Whether just provide binning method to guest party. If true, host party will do nothing.</span>

<span class="sd">    transform_param: TransformParam</span>
<span class="sd">        Define how to transfer the binned data.</span>

<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">method</span><span class="o">=</span><span class="n">consts</span><span class="o">.</span><span class="n">QUANTILE</span><span class="p">,</span>
                 <span class="n">compress_thres</span><span class="o">=</span><span class="n">consts</span><span class="o">.</span><span class="n">DEFAULT_COMPRESS_THRESHOLD</span><span class="p">,</span>
                 <span class="n">head_size</span><span class="o">=</span><span class="n">consts</span><span class="o">.</span><span class="n">DEFAULT_HEAD_SIZE</span><span class="p">,</span>
                 <span class="n">error</span><span class="o">=</span><span class="n">consts</span><span class="o">.</span><span class="n">DEFAULT_RELATIVE_ERROR</span><span class="p">,</span>
                 <span class="n">bin_num</span><span class="o">=</span><span class="n">consts</span><span class="o">.</span><span class="n">G_BIN_NUM</span><span class="p">,</span> <span class="n">cols</span><span class="o">=-</span><span class="mi">1</span><span class="p">,</span> <span class="n">adjustment_factor</span><span class="o">=</span><span class="mf">0.5</span><span class="p">,</span>
                 <span class="n">transform_param</span><span class="o">=</span><span class="n">TransformParam</span><span class="p">(),</span>
                 <span class="n">local_only</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                 <span class="n">need_run</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">(</span><span class="n">FeatureBinningParam</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">=</span> <span class="n">method</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">compress_thres</span> <span class="o">=</span> <span class="n">compress_thres</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">head_size</span> <span class="o">=</span> <span class="n">head_size</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">error</span> <span class="o">=</span> <span class="n">error</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">adjustment_factor</span> <span class="o">=</span> <span class="n">adjustment_factor</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">bin_num</span> <span class="o">=</span> <span class="n">bin_num</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">cols</span> <span class="o">=</span> <span class="n">cols</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">local_only</span> <span class="o">=</span> <span class="n">local_only</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">transform_param</span> <span class="o">=</span> <span class="n">copy</span><span class="o">.</span><span class="n">deepcopy</span><span class="p">(</span><span class="n">transform_param</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">need_run</span> <span class="o">=</span> <span class="n">need_run</span>

<div class="viewcode-block" id="FeatureBinningParam.check"><a class="viewcode-back" href="../../../federatedml.param.html#federatedml.param.feature_binning_param.FeatureBinningParam.check">[docs]</a>    <span class="k">def</span> <span class="nf">check</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">descr</span> <span class="o">=</span> <span class="s2">&quot;hetero binning param&#39;s&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">check_string</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">method</span><span class="p">,</span> <span class="n">descr</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">method</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">check_valid_value</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">method</span><span class="p">,</span> <span class="n">descr</span><span class="p">,</span> <span class="p">[</span><span class="n">consts</span><span class="o">.</span><span class="n">QUANTILE</span><span class="p">])</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">check_positive_integer</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">compress_thres</span><span class="p">,</span> <span class="n">descr</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">check_positive_integer</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">head_size</span><span class="p">,</span> <span class="n">descr</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">check_decimal_float</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">error</span><span class="p">,</span> <span class="n">descr</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">check_positive_integer</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">bin_num</span><span class="p">,</span> <span class="n">descr</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">check_defined_type</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">cols</span><span class="p">,</span> <span class="n">descr</span><span class="p">,</span> <span class="p">[</span><span class="s1">&#39;list&#39;</span><span class="p">,</span> <span class="s1">&#39;int&#39;</span><span class="p">,</span> <span class="s1">&#39;RepeatedScalarContainer&#39;</span><span class="p">])</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">check_open_unit_interval</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">adjustment_factor</span><span class="p">,</span> <span class="n">descr</span><span class="p">)</span></div></div>

</pre></div>

           </div>
           
          </div>
          <footer>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2019, FATE_TEAM

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>